<template>
  <div>
    <a-card>
      <a-form :form="form">
        <a-row>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="教职工类别"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['jzglbm',
                {
                  rules: [{ required: true, message: '请选择教职工类别!' }],
                }]">
                <a-select-option v-for="i in TYPE0049" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="职工编号"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="[
                'gh',
                {
                  rules: [{ required: true, message: '请输入职工编号!' }],
                }
              ]" :disabled="!!editId" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="姓名"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['xm',
                {
                  rules: [{ required: true, message: '请输入导师姓名!' }],
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="教师状态"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select mode="multiple" allowClear v-decorator="['dqztm',
                {
                  rules: [{ required: true, message: '请选择教师状态!' }],
                }]">
                <a-select-option v-for="i in TYPE0320" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="姓名拼音"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['xmpy']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="英文姓名"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['ywxm']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="曾用名"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['cym']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="性别"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select allowClear v-decorator="['xbm',
                {
                  rules: [{ required: true, message: '请选择性别!' }],
                }]">
                <a-select-option v-for="i in TYPE0011" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="身份证件类型"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select allowClear v-decorator="['sfzjlxm']">
                <a-select-option v-for="i in TYPE0088" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="身份证件号"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['sfzjh',
                {
                  rules: [{ required: true, message: '请输入身份证件号!' }],
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="证件有效期"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-date-picker v-decorator="['sfzjyxq']" style="width: 100%" format="YYYY-MM-DD"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="出生日期"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-date-picker v-decorator="['csrq',
                {
                  rules: [{ required: true, message: '请选择出生日期!' }],
                }]" style="width: 100%" format="YYYY-MM-DD"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="国籍"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select allowClear v-decorator="['gjm']">
                <a-select-option v-for="i in TYPE0015" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="民族"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select allowClear v-decorator="['mzm']">
                <a-select-option v-for="i in TYPE0017" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="政治面貌"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['zzmmm']">
                <a-select-option v-for="i in TYPE0020" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="宗教信仰"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['xyzjm']">
                <a-select-option v-for="i in TYPE0001" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="港澳台侨"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['gatqwm']">
                <a-select-option v-for="i in TYPE0037" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="婚姻状况"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['hyzkm']">
                <a-select-option v-for="i in TYPE0012" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="健康状况"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['jkzkm']">
                <a-select-option v-for="i in TYPE0013" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="血型"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['xxm']">
                <a-select-option v-for="i in TYPE0078" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item style="width:100%" selfUpdate label="籍贯" :labelCol="{span: 7,offset: 1}" :wrapperCol="{span: 16}">
              <a-select style="width:33%" @change="provinceNativeChange" v-decorator="['jgsdm']" allowClear>
                <a-select-option v-for="i in selectMenu.province" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
              <a-select style="width:33%" @change="cityNativeChange" v-decorator="['jgcdm']" allowClear>
                <a-select-option v-for="i in selectMenu.nativeCity" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
              <a-select style="width:33%" v-decorator="['jgxqdm']" allowClear>
                <a-select-option v-for="i in selectMenu.nativeArea" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item style="width:100%" label="出生地" :labelCol="{span: 7,offset: 1}" :wrapperCol="{span: 16}">
              <a-select style="width:33%" @change="provinceChange" v-decorator="['csdsm']" allowClear>
                <a-select-option v-for="i in selectMenu.province" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
              <a-select style="width:33%" @change="cityChange" v-decorator="['csdcm']" allowClear>
                <a-select-option v-for="i in selectMenu.city" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
              <a-select style="width:33%" v-decorator="['csdqxm']" allowClear>
                <a-select-option v-for="i in selectMenu.area" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="户口类型"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['hklbm']">
                <a-select-option v-for="(i,index) in TYPE0002" :key="index" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="户口所在地"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['hkszd']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="家庭地址"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['jtzz']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="文化程度"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['whcdm']">
                <a-select-option v-for="(i,index) in TYPE0018" :key="index" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="参加工作年月"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-month-picker v-decorator="['cjgzny']" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="来校日期"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-date-picker v-decorator="['lxrq']" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="起薪日期"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-date-picker v-decorator="['qxrq']" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="从教年月"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-month-picker v-decorator="['cjny']" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="任课状况"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['rkzkm',
                {
                  rules: [{ required: true, message: '请选择任课状况!' }],
                }]">
                <a-select-option v-for="(i,index) in TYPE0063" :key="index" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="最后学历"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['zgxlm',
                {
                  rules: [{ required: true, message: '请选择最后学历!' }],
                }]">
                <a-select-option v-for="(i,index) in TYPE0018" :key="index" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="最后学位"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['zhxwm',
                {
                  rules: [{ required: true, message: '请选择最后学位!' }],
                }]">
                <a-select-option v-for="(i,index) in TYPE0023" :key="index" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="毕业院校或机构"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select style="width:50%" @change="handlePChange" v-decorator="['byxxszsf']" allowClear>
                <a-select-option v-for="i in selectMenu.province" :key="i.areaCode" :value="String(i.areaCode)">{{ i.name }}</a-select-option>
              </a-select>
              <a-select style="width:50%" v-decorator="['byxxdm']" allowClear>
                <a-select-option v-for="i in selectMenu.schoolList" :key="i.xxdm" :value="String(i.xxdm)">{{ i.xxmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="毕业年月"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-month-picker v-decorator="['byny']" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="通讯地址"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['txdz']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="所属院系"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['dwh',
                {
                  rules: [{ required: true, message: '请选择所属院系' }],
                }]" @change="yxChange" showSearch :filterOption="filterOption">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="所属专业"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['zyh',
                {
                  rules: [{ required: true, message: '请选择所属专业!' }],
                }]" showSearch :filterOption="filterOption">
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="定职时间"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-date-picker v-decorator="['dzsj']" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="职称"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-select v-decorator="['zc',
                {
                  rules: [{ required: true, message: '请选择职称' }],
                }]">
                <a-select-option v-for="(i,index) in TYPE0342" :key="index" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="手机号码"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['lxdh']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="住宅电话"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['zzdh']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="办公电话"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['bgdh']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="邮政编码"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['yzbm']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="电子邮箱"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['dzxx']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="主页地址"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['zydz']"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师资助科研经费账号"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
              selfUpdate
            >
              <a-input v-decorator="['dszzkyjfzh']"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-form-item label="个人简介" selfUpdate :labelCol="{span: 4,offset: 1}" :wrapperCol="{span: 19}">
          <a-input type="textarea" v-decorator="['dsjj']" :autosize="{ minRows: 4, maxRows: 6 }"/>
        </a-form-item>
      </a-form>
    </a-card>

    <div class="ant-pro-footer-toolbar">
      <div style="float: right;">
        <a-button style="margin-right: 10px;" @click="back" >返回</a-button>
        <a-button @click="creatTeacher" :loading="loadingBtn" type="primary">保存</a-button>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
const selectArr = ['TYPE0320', 'TYPE0011', 'TYPE0342', 'TYPE0018', 'TYPE0023',
  'TYPE0088', 'TYPE0015', 'TYPE0017', 'TYPE0020', 'TYPE0001', 'TYPE0037', 'TYPE0012', 'TYPE0013', 'TYPE0078', 'TYPE0002', 'TYPE0063', 'TYPE0049']

export default {
  data () {
    return {
      selectMenu: {},
      loadingBtn: false,
      editId: null
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  computed: {
    ...mapState({
      TYPE0011: state => state.app['TYPE0011'], // 性别
      TYPE0320: state => state.app['TYPE0320'], // 导师状态
      TYPE0342: state => state.app['TYPE0342'], // 职称
      TYPE0018: state => state.app['TYPE0018'], // 学历
      TYPE0023: state => state.app['TYPE0023'], // 学位
      TYPE0015: state => state.app['TYPE0015'], // 国籍
      TYPE0017: state => state.app['TYPE0017'], // Minzu
      TYPE0020: state => state.app['TYPE0020'], // 政治面貌
      TYPE0001: state => state.app['TYPE0001'], // 宗教
      TYPE0037: state => state.app['TYPE0037'], // 港澳
      TYPE0012: state => state.app['TYPE0012'], // 婚姻
      TYPE0013: state => state.app['TYPE0013'],
      TYPE0078: state => state.app['TYPE0078'],
      TYPE0002: state => state.app['TYPE0002'],
      TYPE0063: state => state.app['TYPE0063'],
      TYPE0049: state => state.app['TYPE0049'],
      TYPE0088: state => state.app['TYPE0088'] // 身份证类型
    })
  },
  async created () {
    await selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    await this.initSelectMenu()
    if (this.$route.query.gh) {
      this.initForm(this.$route.query.gh)
    }
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$api.base.areaList()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data,
          province: res[1].data
        }
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    initForm (gh) {
      this.$api.cultivate.teacherDetail(gh).then(res => {
        let {data} = res
        if (data.csdsm) {
          this.provinceChange(data.csdsm)
        }
        if (data.csdcm) {
          this.cityChange(data.csdcm)
        }
        if (data.jgsdm) {
          this.provinceNativeChange(data.jgsdm)
        }
        if (data.jgcdm) {
          this.cityNativeChange(data.jgcdm)
        }
        if (data.dwh) {
          this.yxChange(data.dwh)
        }
        if(data.byxxszsf){
          this.handlePChange(data.byxxszsf)
        }
        this.form.setFieldsValue(data)
        this.editId = data.id
      })
    },
    handlePChange(v) {
      this.form.setFieldsValue({byxxdm: ''})
      this.$api.base.schoolInfoQueryAll({xzqhsdm: v}).then(res => {
        this.$set(this.selectMenu, 'schoolList' , res.data)
      })
    },
    provinceChange (v) {
      this.form.setFieldsValue({csdcm: '', csdqxm: ''})
      if (v) {
        this.$api.base.areaList({parentCode: v}).then(res => {
          this.$set(this.selectMenu, 'city', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'city', [])
      }
      this.$set(this.selectMenu, 'area', [])
    },
    cityChange (v) {
      this.form.setFieldsValue({csdqxm: ''})
      if (v) {
        this.$api.base.areaList({parentCode: v}).then(res => {
          this.$set(this.selectMenu, 'area', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'area', [])
      }
    },
    provinceNativeChange (v) {
      this.form.setFieldsValue({jgcdm: '', jgxqdm: ''})
      if (v) {
        this.$api.base.areaList({parentCode: v}).then(res => {
          this.$set(this.selectMenu, 'nativeCity', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'nativeCity', [])
      }
      this.$set(this.selectMenu, 'nativeArea', [])
    },
    cityNativeChange (v) {
      this.form.setFieldsValue({jgxqdm: ''})
      if (v) {
        this.$api.base.areaList({parentCode: v}).then(res => {
          this.$set(this.selectMenu, 'nativeArea', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'nativeArea', [])
      }
    },
    yxChange (code) {
      this.form.setFieldsValue({zyh: ''})
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zy', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zy', [])
      }
    },
    creatTeacher () {
      this.form.validateFields((err, values) => {
        if (err) {
          return
        }
        this.loadingBtn = true
        this.$DateToString(values)
        let apiFn = this.editId ? 'teacherUpdate' : 'teacherAdd'
        if (this.editId) {
          values.id = this.editId
        }
        this.$api.cultivate[apiFn](values).then(res => {
          this.$message.success(res.msg)
          this.$router.back()
        }).finally(() => {
          this.loadingBtn = false
        })
      })
    },
    back() {
      this.$router.back()
    }
  }
}
</script>
